<?php
/**
 * @标签类
 * 1、云端产业
 * 2、云端产业详情
 * 3、城市
 * 4、行业
 * 5、平台或当前用户产业链
 * 6、企业label
 * @作者 
 * 万全强（php）
 */
namespace app\controller;

use app\controller\HomeBase;
use think\facade\Db;


use app\model\ChainModel;
use app\model\CityModel;
use app\model\IndustryModel;
use app\model\CompanylabelModel;


use app\model\AdminRole;
use app\model\Chain;


class Label extends HomeBase
{

    private $ChainModel;
    private $CityModel;
    private $IndustryModel;
    private $CompanylabelModel;

    public function __construct(){
               
        parent::__construct();        
    }

    /**
     * 1、云端产业链
     */
    public function GetChainInfo(){
        
        
        $id=request()->param('chain_id',0,'intval');

        $this->ChainModel=new ChainModel();
        $res=$this->ChainModel->GetInfo($id);

        return json(['status'=>1,'msg'=>'获取成功','data'=>$res]);
    }
    /**
     * 2、云端产业链详情
     */
    public function GetChainDetailById(){
    	
    	
    	$id=request()->param('chain_id',0,'intval');
    	
    	$this->ChainModel=new ChainModel();
    	$res=$this->ChainModel->GetDetail($id);
    	
    	return json(['status'=>1,'msg'=>'获取成功','data'=>$res]);
    }
     /**
     *3、城市
     */
    public function GetCityInfo(){
        
        $id=request()->param('city_id',0,'intval');

      

        $this->CityModel=new CityModel();
        $res=$this->CityModel->GetInfo($id);
        
        return json(['status'=>1,'msg'=>'获取成功','data'=>$res]);
    }
     /**
     *4、行业
     */
    public function GetIndustryInfo(){
        
        $id=request()->param('industry_id',0,'intval');

        $this->IndustryModel=new IndustryModel();
        $res=$this->IndustryModel->GetInfo($id);
        
        return json(['status'=>1,'msg'=>'获取成功','data'=>$res]);
    }
    /**
     *5、平台或当前用户产业链
     */
    public function GetUserOrPlatformChain(){
        $id=request()->param('id',0,'intval');
        $RoleChain=new Chain();
        if(!empty($id)){
            $chain=$RoleChain->GetChain($id,'1=1','id,chain_id,chain_name,pid');//当前产业链
            $Chain=arr2tree($chain,0,'chain_name','id');
            return json(['status'=>1,'msg'=>'获取成功','data'=>$Chain]);
        }  
       
        if($this->user_id){
            $AdminRole=new AdminRole();
            $role_ids=$AdminRole->GetRole($this->user_id);    
            if(!empty($role_ids)){
                $chain=$RoleChain->GetChain($role_ids[0],'1=1','id,chain_id,chain_name,pid');//当前产业链
                $Chain=arr2tree($chain,0,'chain_name','id');
                return json(['status'=>1,'msg'=>'获取成功','data'=>$Chain]);
            }
        }

        return json(['status'=>1,'msg'=>'获取成功','data'=>[]]);
    }
    /**
     * 6、企业label
     */
    public function GetCompanylabelInfo(){
    	
    	
    	$chain_id=request()->param('chain_id',0,'intval');
    	$city_id=request()->param('city_id',0,'intval');
    	
    	$this->CompanylabelModel=new CompanylabelModel();
    	$res=$this->CompanylabelModel->GetInfo($chain_id);
    	
    	return json(['status'=>1,'msg'=>'获取成功','data'=>$res]);
    }

}